﻿package mortal.game.view.rebate.openNewSerSevenDay.panels
{
    import baseEngine.modifiers.*;
    import com.mui.controls.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class OpenNewSerSevMid extends GSprite
    {
        protected var _bg:GImageBitmap;
        protected var _power:BitmapNumberText;
        protected var _title:GImageBitmap;
        private var _powArr:Array;
        private var _window:IWindow3D;
        private var _rect3d:Rect3DObject;
        private var _effect:EffectPlayer;
        private var _img2d:Img2D;
        private var _wid:int = 688;
        private var _hei:int = 201;
        private var _posArr:Array;
        private var _isFirst:Boolean = true;
        private var _eff:String;

        public function OpenNewSerSevMid(param1:IWindow3D)
        {
            this._powArr = [20000, 1000, 1888, 1888, 1888, 1888, 1888, 1888, 1888];
            this._posArr = [346, 113];
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._power = UIFactory.bitmapNumberText(573, 51, "OpenNewSerSevNum2.png", 20, 26, -2, this, 10, 0);
            this._power.text = "(1888";
            this._title = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZMidT1, 35, 32, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._eff = null;
            this._isFirst = true;
            this._bg = null;
            this._power = null;
            this._title = null;
            this.remove3D();
            super.disposeImpl(param1);
            return;
        }// end function

        private function add3DRect() : void
        {
            var _loc_1:Point = null;
            if (this._rect3d == null)
            {
                _loc_1 = new Point(205, 123);
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(_loc_1.x, _loc_1.y, this._wid, this._hei), this._window);
                Rect3DManager.instance.windowShowHander(null, this._window);
            }
            return;
        }// end function

        public function upateInfo(param1:int) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this.updateBg(param1);
            this.updateModel(param1);
            this.updateTitle(param1);
            this.updatePower(param1);
            return;
        }// end function

        private function updateBg(param1:int) : void
        {
            if (this._bg)
            {
                this._bg.dispose();
            }
            var _loc_2:String = "";
            if (param1 == 99 || param1 == 100)
            {
                _loc_2 = ImagesConst.OpenNewSerSevZMidBg + "_" + param1;
            }
            else
            {
                _loc_2 = ImagesConst.OpenNewSerSevZMidBg;
            }
            this._bg = UIFactory.gImageBitmap(_loc_2, 0, 0, null, this.onBgLoadCompl);
            return;
        }// end function

        private function updateTitle(param1:int) : void
        {
            this._title.imgUrl = "OpenNewSerSevZMidT" + param1;
            return;
        }// end function

        private function updatePower(param1:int) : void
        {
            var _loc_2:* = param1;
            if (param1 == 99)
            {
                _loc_2 = 0;
            }
            else if (param1 == 100)
            {
                _loc_2 = 1;
            }
            else
            {
                _loc_2 = param1 + 1;
            }
            this._power.text = "(" + this._powArr[_loc_2];
            return;
        }// end function

        private function updateModel(param1:int) : void
        {
            var _loc_2:* = OpenServerSevenDayUtil.getEffByDay(param1);
            this.addMode(_loc_2);
            return;
        }// end function

        private function addMode(param1:String) : void
        {
            this._eff = param1;
            if (param1 == null || param1 == "")
            {
                if (this._effect)
                {
                    this._rect3d.disposeObj3d(this._effect);
                }
                return;
            }
            if (this._rect3d)
            {
                if (this._effect)
                {
                    this._rect3d.disposeObj3d(this._effect);
                }
                this._effect = EffectPlayerPool.instance.getEffectPlayer(param1, null, this._rect3d.renderList, false);
                this._effect.hangBoneName = BoneConst.MountHangModelBone;
                this._effect.play(PlayMode.ANIMATION_LOOP_MODE);
                this._rect3d.addObject3d(this._effect, this._posArr[0], this._posArr[1]);
                this._effect.name = "midPlayer";
            }
            return;
        }// end function

        protected function onBgLoadCompl() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.add3DRect();
            this.addImg();
            if (this._isFirst)
            {
                this._isFirst = false;
                this.addMode(this._eff);
            }
            return;
        }// end function

        private function addImg() : void
        {
            if (this._bg == null || this._bg.bitmapData == null)
            {
                return;
            }
            if (this._rect3d)
            {
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                }
                this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, this._wid, this._hei), false);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        private function remove3D() : void
        {
            if (this._rect3d)
            {
                if (this._effect)
                {
                    this._rect3d.disposeObj3d(this._effect);
                    this._effect = null;
                }
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                    this._img2d = null;
                }
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

    }
}
